package chapter10.clone;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2018-03-22 下午1:41
 */
public class CloneTest {
    private static final Logger LOGGER = LoggerFactory.getLogger(CloneTest.class);

    public static void main(String[] args) {
        Company c = new Company();
        c.setName("abc");

        School school = new School();
        school.setName("dd");

        Person p1 = new Person();
        p1.setName("test1");
        p1.setAge(21);
        p1.setCompany(c);
        p1.setSchool(school);

        try {
            Person p2 = (Person) p1.clone();
            LOGGER.info("----- p2 clone p1 -----");
            LOGGER.info("p1:{}", p1.toString());
            LOGGER.info("p2:{}", p2.toString());


            LOGGER.info("----- revise p2 -----");
            p2.setName("test2");
            p2.setAge(13);
            LOGGER.info("p1:{}", p1.toString());
            LOGGER.info("p2:{}", p2.toString());

            LOGGER.info("String in clone is deep clone?:{}", "test1".equals(p1.getName()));

            LOGGER.info("Object not implement colneable interface in clone is deep clone?:{}", p1.getCompany() != p2.getCompany());

            LOGGER.info("Object implement colneable interface in clone is deep clone?:{}", p1.getSchool() != p2.getSchool());

        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }

    }
}
